package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SignRule;
import com.ruoyi.system.service.ISignRuleService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 签到规则Controller
 * 
 * @author kinglu
 * @date 2021-11-30
 */
@RestController
@RequestMapping("/SignRule")
public class SignRuleController extends BaseController
{
    @Autowired
    private ISignRuleService signRuleService;

    /**
     * 查询签到规则列表
     */
    @RequiresPermissions("system:SignRule:list")
    @GetMapping("/list")
    public TableDataInfo list(SignRule signRule)
    {
        startPage();
        List<SignRule> list = signRuleService.selectSignRuleList(signRule);
        return getDataTable(list);
    }

    /**
     * 导出签到规则列表
     */
    @RequiresPermissions("system:SignRule:export")
    @Log(title = "签到规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SignRule signRule)
    {
        List<SignRule> list = signRuleService.selectSignRuleList(signRule);
        ExcelUtil<SignRule> util = new ExcelUtil<SignRule>(SignRule.class);
        util.exportExcel(response, list, "签到规则数据");
    }

    /**
     * 获取签到规则详细信息
     */
    @RequiresPermissions("system:SignRule:query")
    @GetMapping(value = "/{signTimes}")
    public AjaxResult getInfo(@PathVariable("signTimes") Long signTimes)
    {
        return AjaxResult.success(signRuleService.selectSignRuleBySignTimes(signTimes));
    }

    /**
     * 新增签到规则
     */
    @RequiresPermissions("system:SignRule:add")
    @Log(title = "签到规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SignRule signRule)
    {
        return toAjax(signRuleService.insertSignRule(signRule));
    }

    /**
     * 修改签到规则
     */
    @RequiresPermissions("system:SignRule:edit")
    @Log(title = "签到规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SignRule signRule)
    {
        return toAjax(signRuleService.updateSignRule(signRule));
    }

    /**
     * 删除签到规则
     */
    @RequiresPermissions("system:SignRule:remove")
    @Log(title = "签到规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{signTimess}")
    public AjaxResult remove(@PathVariable Long[] signTimess)
    {
        return toAjax(signRuleService.deleteSignRuleBySignTimess(signTimess));
    }
}
